package cn.hchaojie.camp.week1.qa;

public class Ex9MonthDays {
	private static final int[][] TEST_DATA = {
			{2018, 2},
			{2018, 4},
			{2018, 3},
			{2016, 2},
			{2016, 3},
			{2000, 2},
			{2000, 3},
			{1900, 2},
			{1900, 12},
			{2100, 2},
			{2100, 7},
			{2100, 8},
	};
	public static void main(String[] args) {
		for (int i = 0 ; i < TEST_DATA.length; i++) {
			int year = TEST_DATA[i][0];
			int month = TEST_DATA[i][1];
			System.out.println(year + "年" + month + "月：" + getDays(year, month));
		}
	}
	
	public static int getDays(int year, int month) {
		switch (month) {
		case 1:
		case 3:
		case 5:
		case 7:
		case 8:
		case 10:
		case 12:
			return 31;

		case 2:
			return isLeapYear(year) ? 29 : 28;

		case 4:
		case 6:
		case 9:
		case 11:
			return 30;

		default:
			System.out.println("错误的月份！");
			return 0;
		}
	}
	
	public static boolean isLeapYear(int year) {
		return year % 4 == 0 && year % 100 != 0 || year % 400 == 0;
	}
}
